package com.xja.springboot.service.impl;


import com.xja.springboot.entity.Chatuser;
import com.xja.springboot.mapper.ChatuserMapper;
import com.xja.springboot.service.ChatuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service("chatuserService")
public class ChatuserServiceImpl implements ChatuserService {
    @Autowired
    private ChatuserMapper chatuserMapper;

    @Override
    @Transactional(readOnly = true)
    public Chatuser selectByUserId(String userId) throws Exception {
        return chatuserMapper.selectByUserId(userId);
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED)
    public void addChatUser(Chatuser chatuser) throws Exception {
        chatuser.setStatus(1);
        chatuser.setFirsttime(new Date());
        chatuserMapper.insertSelective(chatuser);
    }

    @Override
    public Chatuser selectUserById(Integer id) throws Exception {
        return chatuserMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateUser(Chatuser chatuser) throws Exception {
        chatuserMapper.updateByPrimaryKeySelective(chatuser);
    }
}
